package com.lazydong.apiforward.gateway.environment;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.env.EnvironmentPostProcessor;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.PropertiesPropertySource;

import java.util.Properties;

public class UseInsecureTrustManagerEnvironment implements EnvironmentPostProcessor {

    @Override
    public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
        Properties properties = new Properties();
        // spring.cloud.gateway.httpclient.ssl.use-insecure-trust-manager 要设置为 true，才能使用自定义的 SslContext
        properties.put("spring.cloud.gateway.httpclient.ssl.use-insecure-trust-manager", "true");
        PropertiesPropertySource propertiesPropertySource = new PropertiesPropertySource("use-insecure-trust-manager", properties);
        environment.getPropertySources().addLast(propertiesPropertySource);
    }
}
